<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>二级页面</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache"> 
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" href="<%=basePath %>/static/yzyx/css/subpage.css" />
		<script type="text/javascript" src="<%=basePath%>static/jquery-1.11.2.min.js" />
	</head>
	<body>
		<!--在线咨询-->
		<div class="seven">
			<div class="together"><span class="font">&#xe60b;</span>
				<p><a href="">在线咨询</a></p>
			</div>
		</div>
		<!--头部部分-->
		<div id="body_top">
			<img src="<%=basePath %>/static/yzyx/images/icon_02.png">
			<a></a>
		</div>
		<div id="body">
			<div class="name">新生须知</div>
			<div class="body">
				<div class="body_left">
					<ul>
						<li><img src='<%=basePath %>/static/yzyx/images/la4.png'><span class="span">大学校园初体验</span><span class="font">&#xe601;</span></li>
						<li class="top"><img src='<%=basePath %>/static/yzyx/images/la5.png'><span class="span">大学生活全接触</span><span class="font">&#xe601;</span></li>
						<li class="top"><img src='<%=basePath %>/static/yzyx/images/la6.png'><span class="span">延伸阅读</span><span class="font">&#xe601;</span></li>
					</ul>
					<img src='<%=basePath %>/static/yzyx/images/book (2).png'>
				</div>
				<div class="body_right">
					<div class="time">校园公告</div>
					<div class="neirong">
						<ul>
							<c:forEach items="${news }" var="news" varStatus="status">
								<li id="${news.id }">
									<a>${news.title}</a>
									<a>
									<fmt:formatDate pattern="yyyy-MM-dd" value="${news.pubTime}" />
									</a>
								</li>
							</c:forEach>
						</ul>
					</div>
					<div class="tiaozhuan">
						<div class="up"><a>上一页</a></div>
						<div class="number">
							<ul>
								<c:if test="${maxPage<=5}">
									<c:forEach var="s"  begin="1" end="${maxPage}">
										<li id='${s}'>${s}</li> 
									</c:forEach>
								</c:if>
								<c:if test="${maxPage>5}">
									<c:forEach var="s"  begin="1" end="5">
										<li id='${s}'>${s}</li> 
									</c:forEach>
								</c:if>
							</ul>
						</div>
						<div class="down"><a>下一页</a></div>
						<div class="tiao">
							<span>共${maxPage }页,到第</span>
							<input type="number" value="1" min='1' max='${maxPage}'/>
							<span>页</span>
							<button class="btn">确定<tton>
						</div>
					</div>
					
				</div>
			</div>
			
		</div>
	</body>
</html>
<script type="text/javascript" >
	Date.prototype.format = function (fmt) { //author: meizz 
	    var o = {
	        "M+": this.getMonth() + 1, //月份 
	        "d+": this.getDate(), //日 
	        "h+": this.getHours(), //小时 
	        "m+": this.getMinutes(), //分 
	        "s+": this.getSeconds(), //秒 
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	        "S": this.getMilliseconds() //毫秒 
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	}

	var pageno = 1;
	var maxPage = parseInt($(".tiao input").attr("max"));
	
	$(document).on('click','.neirong ul li',function(){
		  //获取所需要的值
	      var newid = $(this).attr("id");
	      window.open("${basePath}s/notify.html?newid="+newid);
	});
	function changeno(page,max){
		var rootNo = $(".number ul");
		if(max>5&&page>3){
			if((page+2)<=max){
				rootNo.empty();
				for(var i=(page-2);i<(page+3);i++){
					var li = $("<li id='"+i+"'>"+i+"</li>");
					rootNo.append(li);
				}
			}else{
				rootNo.empty();
				for(var i=(max-4);i<=max;i++){
					var li = $("<li id='"+i+"'>"+i+"</li>");
					rootNo.append(li);
				}
			}
		}else if(max>5&&page<=3){
			rootNo.empty();
			for(var i=1;i<6;i++){
				var li = $("<li id='"+i+"'>"+i+"</li>");
				rootNo.append(li);
			}
		}
		rootNo.find("li[id='"+page+"']").css({"background":"#ccc","color":"#000"});
	};

	$(document).on('click','.number li',function(){
		pageno = parseInt($(this).attr("id"));
		$.post("${basePath}s/newsByPageNo", {pageno:pageno}, function (data) {
	          if(data.length>0){
	          	var root = $(".neirong ul");
	          	root.empty();
	          	for(var i=0;i<data.length;i++){
	          		var pubTimeStr = new Date(data[i].pubTime).format("yyyy-MM-dd");
					var li = $("<li id='"+data[i].id+"'><a>"+data[i].title+"</a><a>"+pubTimeStr+" </a></li> ");
	          		root.append(li);
	          	}
	          	changeno(pageno,maxPage);
	          }
		 });
	});

	$(document).on('click','.up',function(){
		  pageno=pageno-1;
		  if(pageno>=1){
		      $.post("${basePath}s/newsByPageNo", {pageno:pageno}, function (data) {
		          if(data.length>0){
		          	var root = $(".neirong ul");
		          	root.empty();
		          	for(var i=0;i<data.length;i++){
		          		var pubTimeStr = new Date(data[i].pubTime).format("yyyy-MM-dd");
						var li = $("<li id='"+data[i].id+"'><a>"+data[i].title+"</a><a>"+pubTimeStr+" </a></li> ");
		          		root.append(li);
		          	}
		          }
		      });
		  }else{
		  	pageno=1;
		  }
		  changeno(pageno,maxPage);
	});
	$(document).on('click','.down',function(){
		  pageno=pageno+1;
		  if(pageno<=maxPage){
		      $.post("${basePath}s/newsByPageNo", {pageno:pageno}, function (data) {
		          if(data.length>0){
		          	var root = $(".neirong ul");
		          	root.empty();
		          	for(var i=0;i<data.length;i++){
		          		var pubTimeStr = new Date(data[i].pubTime).format("yyyy-MM-dd");
						var li = $("<li id='"+data[i].id+"'><a>"+data[i].title+"</a><a>"+pubTimeStr+" </a></li> ");
		          		root.append(li);
		          	}
		          }
		      });
		  }else{
		  	pageno=maxPage;
		  }
	     changeno(pageno,maxPage);
	});
	
	$(document).on('click','.btn',function(){
	  	  no = parseInt($(this).closest("div").find("input[type='number']").val());
	  	  if(no<1||no>maxPage)
	  	  	return ;
	  	  pageno=no;
	      $.post("${basePath}s/newsByPageNo", {pageno:pageno}, function (data) {
	      	if(data.length>0){
	          	var root = $(".neirong ul");
	          	root.empty();
	          	for(var i=0;i<data.length;i++){
	          		var pubTimeStr = new Date(data[i].pubTime).format("yyyy-MM-dd");
					var li = $("<li id='"+data[i].id+"'><a>"+data[i].title+"</a><a>"+pubTimeStr+" </a></li> ");
	          		root.append(li);
	          	}
	          }
	      });
	      changeno(pageno,maxPage);
	});
	$(function(){
		$(".number ul").find("li[id='1']").css({"background":"#ccc","color":"#000"});
	});
	var height=$(window).height();
	var martop=height*0.80+'px';
	var martop2=height*0.50+'px';
	var martop3=height*0.80-40+'px';
	$('#body').css('height',martop);
	$('.body_left').css('height',martop3);
	$('.neirong').css('height',martop2);
	$('.body').css('height',martop);

	
</script>
